﻿function $$(nameid, area) {
    return typeof nameid == 'object' ? mini.get(nameid) : nameid.substr(0, 1) == '#' ? mini.get(nameid, area) : mini.getbyName(nameid, area);
}
function autocomplete_keydown(e) {
    e.sender.OO1O0.value = e.sender.OO1O0.value.replace(/^\s/, '').replace(/\s$/, '');
    if (e.sender.OO1O0.value) {
        if (e.htmlEvent.keyCode == 13) return; //回车
        if (e.htmlEvent.keyCode == 38) return; //↑
        if (e.htmlEvent.keyCode == 40) return; //↓
        if (e.htmlEvent.keyCode == 113) return; //F2
    }
    if (e.htmlEvent.ctrlKey == true) {
        if (e.htmlEvent.keyCode == 86) return; //v
    }
    e.htmlEvent.keyCode = 27;  //关闭搜索框
    //autocomplete_keydown.last = e.sender.OO1O0.value;
}
uap({
    loading: function (v) {
        top.mini.hideMessageBox(uap._loading_task);
        if (v) {
            uap._loading_task = top.mini.loading(v, 'loading');
        }
    }
    , win: function (url, title, width, height, e, option) {
        if (!url) return;
        if (e === true) {
            return window.open(url, title);
        }
        var _w = {
            url: url,
            title: title ? title : 'uap',
            width: width ? width : 420,
            height: height ? height : 280,
            iconCls: 'icon-help',
            allowResize: false,
            showMaxButton: url.substr(url.length - 1) == '#'
        };
        if (option) {
            for (var k in option) {
                _w[k] = option[k];
            }
        }
        var ol, od;
        try {
            if ('function' == typeof e) {
                ol = null;
                od = e;
            } else {
                ol = e[0];
                od = e[1];
            }
        } catch (we) { }
        _w.onload = function () {
            var iframe;
            try {
                iframe = this.getIFrameEl();
            } catch (_e) {
                return;
            }
            try {
                uap.document.noMenu(iframe.contentWindow.document);
            } catch (_e) { }
            if (ol) {
                ol(iframe.contentWindow);
            }
        };
        _w.ondestroy = function (d) {
            if (od) {
                if (true === d) od(d);
                if ('object' == typeof d) od(d);
            }
        };
        return top.mini.open(_w);
    }
    , prompt: function (msg, e, isMulti, def) {
        top.mini.prompt(msg + "：", "请输入",
                function (action, value) {
                    if (action == "ok") {
                        e(value);
                    }
                },
                isMulti
            );
        $('.mini-messagebox-content textarea').val(def);
    }
    , alert: function (s, f) {
        top.mini.alert(s, '提示', f);
    }
    , confirm: function (s, yes, no) {
        top.mini.confirm(s, '确认', function (ret) {
            if (ret == 'ok') {
                if (yes) yes(ret);
            } else {
                if (no) no();
            }
        });
    }
    , skin: function (v) {
        if (!v) v = 'none';
        var url = uap_res + "/themes/" + v + "/skin.css", skinEl = document.getElementById(uap_skin);
        this.cookie.set(uap_skin, v);
        if (skinEl) {
            skinEl.parentNode.removeChild(skinEl);
        }
        if (v != 'none') {
            var link = document.createElement("link");
            link.id = uap_skin;
            link.setAttribute("rel", "stylesheet");
            link.setAttribute("type", "text/css");
            link.setAttribute("href", url);
            var heads = document.getElementsByTagName("head");
            if (heads.length) {
                heads[0].appendChild(link);
            } else {
                document.documentElement.appendChild(link);
            }
        }
        //处理iframe
        var i, ii = window.frames.length;
        for (var i = 0; i < ii; i++) {
            try {
                var win = window.frames[i].window; //window.frames[i].contentWindow;
                if (win.uap.skin) {
                    win.uap.skin(v);
                }
            } catch (e) {
            }
        }
    }
    , asLabel: function (form, v) {
        var fs = form.getFields();
        for (var i = 0, l = fs.length; i < l; i++) {
            var c = fs[i];
            if (c.setReadOnly) c.setReadOnly(v);
            if (v) {
                if (c.setIsValid) c.setIsValid(v);
                if (c.addCls) c.addCls("asLabel");
            } else {
                if (c.removeCls) c.removeCls("asLabel");
                mini.repaint(document.body);
            }
        }
    }
    , ui: {
        datagrid: {
            search: function (url, option, tit, duplicate) {
                var v = 'autosearch', u = window.location.toString(), id = u.replace(/[^a-z]/g, '');
                uap.cookie.set(v, toUAP(option));
                url += (url.indexOf('?') > 0 ? '&' : '?') + '@=' + v;
                if (duplicate) {
                    id = id + Math.random().toString().replace('.', '');
                }
                uap.newTab(id, url, tit ? tit : '搜索');
            }
        }
    }
    , newTab: function (id, url, text) {
        if (top) {
            if (top['main']) {
                if (top.main['newTab']) {
                    top.main.newTab(id, text, url);
                    return;
                }
            }
        }
        window.open(url);
    }
});
var uap_skin = 'uap_skin';
document.write('<script src="' + uap_res + '/i.js" type="text/javascript"></sc' + 'ript>');
document.write('<link href="' + uap_res + '/themes/default/miniui.css" rel="stylesheet" type="text/css" />');
document.write('<link href="' + uap_res + '/themes/icons.css" rel="stylesheet" type="text/css" />');
var skin = uap.cookie.get(uap_skin, true);
if (skin) if (skin != 'none') uap.skin(skin);
uap.init.push(function () {
    var x = 'ie88';
    window[x] = function (iv) {
        if (uap.cookie.get('mk')) {
            if ((+new Date()) - uap.cookie.get('mk') < 180000) {
                return;
            }
        }
        top.mini.open({
            url: "/!/IE886.htm?iv=" + iv,
            title: "提示",
            width: 600,
            height: 200,
            allowResize: false
        });
        uap.cookie.set('mk', +new Date());
    };
    return function () {
        var nua = navigator.userAgent.toLowerCase(), iev = nua.indexOf('msie');
        if (nua.indexOf('webkit') < 0) {
            if ("undefined" == typeof Worker) {
                if (iev > 0) {
                    iev = parseFloat(nua.substr(iev + 5).replace(/([\d\.]+)[\s\S]+/g, '$1'));
                    if (iev < 8) {
                        var wt = setInterval(function () {
                            if ('object' == typeof mini) {
                                if (mini['open']) {
                                    clearInterval(wt);
                                    top[x](iev);
                                }
                            }
                        }, 1000);
                    }
                }
            }
        }
        return x;
    } ()
})